<?php

namespace App\Model;

use PhalApi\Model\NotORMModel as NotORM;

/*
 * 杂项model层
 * 数据模型层，负责技术层面上对数据信息的提取、存储、更新和删除等操作，数据可来自内存，也可以来自持久化存储媒介，甚至可以是来自外部第三方系统
 */

class Spec extends NotORM {

    public function getTableName($id) {
        return 'archives';
    }

    public function getAll() {

        return $this->getORM()
                        ->select('id,typeid,sortrank,flag,channel,click,title,litpic,pubdate,description,weight')
                        ->where(['arcrank' => 0, 'channel' => -1])
                        ->fetchAll();
    }

    public function getBatch($specid) {

        $sql = "SELECT a.id,a.typeid,a.sortrank,a.flag,a.channel,a.click,a.title,a.litpic,a.pubdate,a.description,a.weight, b.arcid "
                . "FROM dede_archives AS a LEFT JOIN dede_spearc AS b "
                . "ON a.id = b.speid "
                . "WHERE a.id={$specid} AND a.arcrank=0 AND b.state=1";

        return $this->getORM()->queryAll($sql);
    }

}
